package day07;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class HomeWorkDay07 {
    public static void main(String[] args) {
        //第一题
        int max = 1000,min = 1,num1 = 0;
        int num = getRandem(max,min);
        System.out.println(num);
        while (true){
            System.out.println("在"+min+"与"+max+"之间，猜吧");
            int guess = getScanner();
            if (guess!=num){
                if (guess>num){
                    System.out.println("猜大了");
                    if (max>guess){
                        max = guess;
                    }
                }else {
                    System.out.println("猜小了");
                    if (min<guess){
                        min = guess;
                    }
                }
            }else {
                System.out.println("猜对了");
                break;
            }
        }

        //第二题
         char[] vercode = getcharRandem(getRandem());
        String code = stringCharArray(vercode);
        System.out.println(code);

        //第三题
        for (int i = 2; i < 100; i++) {
            onlyprime(i);

        }
        System.out.println();

        //第四题
        while (true) {
            System.out.println("请输入机票价格");
            int price = getScanner();
            System.out.println("请输入月份");
            int month = getScanner();
            System.out.println("请输入舱位1.头等舱2.商务舱3.经济舱");
            int type = getScanner();
            if (calAirPrice(price, month, type) == -1) {
                System.out.println("乱打呢，怎么事");
            } else {
                System.out.println("您的机票价格价格为" + calAirPrice(price, month, type));
                break;
            }
        }

        //第五题
        boolean a = true;
        System.out.println("输入评委数量！！");
        int num2 = getScanner();
        while (a) {
            System.out.println("一共有" + num2 + "个评委，请依次输入评分");
            double[] data = inputData(num2);
            if (!verify(data)) {
                System.out.println("数字不对请重新输入!!");
            }else {
                double mean = arrayMean(data);
                System.out.println(findMax(data));
                System.out.println(findMin(data));
                System.out.println("平均分为" + mean);
                break;
            }
        }
    }
    //生成max---min随机数
    public static int getRandem(int max,int min){
        Random random = new Random();
        int a;
        if (min!=0){
            a = random.nextInt(max)+min;
        }else {
            a = random.nextInt(max+1);
        }
        return a;
    }

    //生成5----10随机数
    private static int getRandem(){
        Random random = new Random();
        int a = random.nextInt(6)+5;
        return a;
    }

    //输入
    public static int getScanner(){
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        return a;
    }

    //生成char数组
    private static char[] getcharRandem(int arraylong){
        Random random = new Random();
        char[] h = stringArray(arraylong);
        for (int i = 0; i < h.length; i++) {
            h[i] = randemChar();
        }
        return h;
    }

    //生成随机码
    private static char randemChar() {
        Random random = new Random();
        char a = 0;
        int e = random.nextInt(3);
        switch (e) {
            case 0:
                char b = (char) (random.nextInt(26) + 65);
                a = b;
                break;
            case 1:
                char c = (char) (random.nextInt(26) + 97);
                a = c;
                break;
            case 2:
                char d = (char) (random.nextInt(9) + 48);
                a = d;
                break;
        }
        return a;
    }

    //cha数组转为字符串
    public static String stringCharArray(char[] array){
        String a = "";
        for (int i = 0; i < array.length; i++) {
            a += array[i];
        }
        return a;
    }

    //创建随机数组
    public static char[] stringArray(int num){
        char[] array = new char[num];
        return array;
    }

    //只判断素数
    private static void onlyprime(int num){
        boolean flag = true;
        for (int i = 2; i <= num/2; i++) {
            if (num%i==0){
                flag = false;
                break;
            }
        }
        if (flag){
            System.out.print(num+"\t");
        }
    }

    //机票价格计算
    private static double calAirPrice(int price, int month,int Type){
        double a = 0.0;
        if (price<0||month<0||month>12||Type<0||Type>3){
            return -1;
        }else {
            if (month>=5&&month<=10){//淡季
                switch (Type) {
                    case 1:
                        a = price * 0.2;
                        break;
                    case 2:
                        a = price * 0.3;
                        break;
                    case 3:
                        a = price * 0.4;
                        break;
                }

            }else {//旺季
                switch (Type) {
                    case 1:
                        a = price * 0.6;
                        break;
                    case 2:
                        a = price * 0.7;
                        break;
                    case 3:
                        a = price * 0.8;
                        break;
                }
            }
        }
        return a;
    }

    //输入评委分数
    public static double[]inputData(int count){
        double[] data = new double[count];
        for (int i = 0; i < data.length; i++) {
            double a = getScanner();
            data[i] = a;
        }
        return data;
    }

    //输出数组总分
    public static double arraySum(double[] array){
        double sum = 0.0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        return sum;
    }

    //输出数组平均分
    public static double arrayMean(double[] array){
        double mean = (arraySum(array)-findMax(array)-findMin(array))/(array.length-2);
        return mean;
    }

    //找到数组中的最大值
    public static double findMax(double[] array) {
        double max = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
        return max;
    }

    //找到数组中的最小值
    public static double findMin(double[] array) {
        double min = 100;
        for (int i = 0; i < array.length; i++) {
            if (array[i] < min) {
                min = array[i];
            }
        }
        return min;
    }

    //输入正确验证
    public static boolean verify(double[] array){
        boolean a = true;
        for (int i = 0; i < array.length; i++) {
            if (array[i]<0||array[i]>100){
                a = false;
            }
        }
        return a;
    }
}



